
<?php
	include_once("../webconfig.php");
	include_once("../DAO/DataHelper.php");
	include_once("../DAO/SanPham_DAO.php");
	include_once("../DAO/DanhMucSanPham_DAO.php");
	
	if(isset($_REQUEST["Sua"]))
	{
		$danhmucsanpham = DanhMucSanPham::ChiTietDanhMuc($_REQUEST["MaDM"]);
		echo "<input id='tbtendm$danhmucsanpham->dm_ma' type='text' value='$danhmucsanpham->dm_ten' />";
	}
	
	if(isset($_REQUEST["HuyCapNhat"]))
	{
		$danhmucsanpham = DanhMucSanPham::ChiTietDanhMuc($_REQUEST["MaDM"]);
		echo "$danhmucsanpham->dm_ten";
	}
	
	if(isset($_REQUEST["CapNhat"]))
	{
		DanhMucSanPham::CapNhatDanhMuc($_REQUEST["MaDM"], $_REQUEST["TenDM"]);
		$danhmucsanpham = DanhMucSanPham::ChiTietDanhMuc($_REQUEST["MaDM"]);
		echo "$danhmucsanpham->dm_ten";
	}
	
	if(isset($_REQUEST["ThemDM"]))
	{
		$ID = DanhMucSanPham::ThemDanhMuc($_REQUEST["TenDM"], $_REQUEST["MaDMCha"]);
		$danhmucsanpham = DanhMucSanPham::ChiTietDanhMuc($ID);
		
		echo "<input id='insert' value='$danhmucsanpham->dm_ma' type='hidden' /><span id='$danhmucsanpham->dm_ma'>$danhmucsanpham->dm_ten</span> <input type='button' id='add$danhmucsanpham->dm_ma' class='add' onclick='Add($danhmucsanpham->dm_ma)' /><input type='button' class='edit' onclick='Sua($danhmucsanpham->dm_ma)' id='edit$danhmucsanpham->dm_ma' /><input id='delete$danhmucsanpham->dm_ma' type='button' class='delete' onclick='Xoa($danhmucsanpham->dm_ma)' /> ";
	}
	if(isset($_REQUEST["Xoa"]))
	{
		$result = DanhMucSanPham::XoaDanhMuc($_REQUEST["MaDM"]);
		if($result == 0)
		{
			echo "<input id='infor' type='hidden' value='0' />";
		}
		else
		{
			$danhmucsanpham = DanhMucSanPham::ChiTietDanhMuc($_REQUEST["MaDM"]);
			echo "$danhmucsanpham->dm_ten<input id='infor' type='hidden' value='1' />";
		}
	}
	
?>